package drawapp.cw.com.recyclerviewdemo;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;

/**
 * Created by lenovo on 2016/12/20.
 */
public class MyGridLayoutManager extends GridLayoutManager implements ILayoutManager {


    public MyGridLayoutManager(BaseRecyclerAdapter adapter,Context context, int spanCount) {
        super(context, spanCount);
        setSpanSizeLookup(new BaseRecyclerAdapter.FooterSpanSize(adapter,this));
    }

    public MyGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
        super(context, spanCount, orientation, reverseLayout);
    }

    @Override
    public boolean loadMore() {
        //第一个可见Item的索引
        int lastVisiableItemIndex = findLastVisibleItemPosition();
        //总共Item的数量
        int totalItemIndex = getItemCount();
        //这里取<=1的时候返回true表示可以加载更多，也就是说当滑动到倒数第二个Item出现的时候就代表可以加载了
        //你也可以写成<5 或者 == 0 随便，由自己的体验来决定
        return totalItemIndex - lastVisiableItemIndex <= 1;
    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return this;
    }

    @Override
    public SpanSizeLookup getSpanSizeLookup() {
        return super.getSpanSizeLookup();
    }

}
